package com.xiaolin.three.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName ViewController
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/10/7
 * @Version 1.0
 */
@Controller
@RequestMapping("/three")
public class ViewController {
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping("/index")
    public String index(@CookieValue(required = false,value = "token")Cookie cookie, HttpSession session){
        if(cookie!=null){
            String token = cookie.getValue();
            Map user = restTemplate.getForObject("http://ssologin.com:8055/sso/getUserInfo?token="+token, Map.class);
                session.setAttribute("user",user);
        }
        return "index";
    }
}
